package com.yanqu.road.entity.banquet.auto;

import com.yanqu.road.entity.DataObject;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 用户自动宴会
 */
public class CrossBanquetAutoData extends DataObject {

    //哪个冲榜活动的
    private int activityId;

    private long userId;

    private int titleAdd;

    private int skillAdd;

    //总的积分最后用邮件发，玩家取消或者活动结束的时候
    private long allIntegral;
    //总的人气，定时下去结算
    private long allPopularity;

    private int joinTimes;

    private long ingots;

    //对应的三种礼物回宴了多少次 用123type2类型代表是哪个
    private Map<Integer,Integer> joinTimesMap = new ConcurrentHashMap<>();

    private long serverId;

    //对应的道具对应的个数t_p_banquet_gift的joinConsume num
    private Map<String,Integer> itemMap = new ConcurrentHashMap<>();

    private List<CrossBanquetAutoJoinLog> joinLogList = new ArrayList<>();


    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public int getTitleAdd() {
        return titleAdd;
    }

    public void setTitleAdd(int titleAdd) {
        if(titleAdd != this.titleAdd){
            this.titleAdd = titleAdd;
            setUpdateOption();
        }
    }

    public int getSkillAdd() {
        return skillAdd;
    }

    public void setSkillAdd(int skillAdd) {
        if(skillAdd != this.skillAdd){
            this.skillAdd = skillAdd;
            setUpdateOption();
        }
    }

    public long getAllIntegral() {
        return allIntegral;
    }

    public void setAllIntegral(long allIntegral) {
        if(allIntegral != this.allIntegral){
            this.allIntegral = allIntegral;
            setUpdateOption();
        }
    }

    public long getAllPopularity() {
        return allPopularity;
    }

    public void setAllPopularity(long allPopularity) {
        this.allPopularity = allPopularity;
    }

    public int getJoinTimes() {
        return joinTimes;
    }

    public void setJoinTimes(int joinTimes) {
        if(joinTimes != this.joinTimes){
            this.joinTimes = joinTimes;
            setUpdateOption();
        }
    }

    public long getIngots() {
        return ingots;
    }

    public void setIngots(long ingots) {
        if(ingots != this.ingots){
            this.ingots = ingots;
            setUpdateOption();
        }
    }

    public long getServerId() {
        return serverId;
    }

    public void setServerId(long serverId) {
        if(serverId != this.serverId){
            this.serverId = serverId;
            setUpdateOption();
        }
    }

    public Map<Integer, Integer> getJoinTimesMap() {
        return joinTimesMap;
    }

    public void setJoinTimesMap(Map<Integer, Integer> joinTimesMap) {
        this.joinTimesMap = joinTimesMap;
        setUpdateOption();
    }

    public Map<String, Integer> getItemMap() {
        return itemMap;
    }

    public void setItemMap(Map<String, Integer> itemMap) {
        this.itemMap = itemMap;
        setUpdateOption();
    }


    public List<CrossBanquetAutoJoinLog> getJoinLogList() {
        return joinLogList;
    }

    public void setJoinLogList(List<CrossBanquetAutoJoinLog> joinLogList) {
        this.joinLogList = joinLogList;
    }

    public void addJoinLog(CrossBanquetAutoJoinLog addLog,int logLimit){
        this.joinLogList.add(addLog);
        joinLogList.sort(new Comparator<CrossBanquetAutoJoinLog>() {
            @Override
            public int compare(CrossBanquetAutoJoinLog o1, CrossBanquetAutoJoinLog o2) {
                return Long.compare(o2.getTime(), o1.getTime());
            }
        });
        //只保留30条
        if(joinLogList.size() > logLimit){
            List<CrossBanquetAutoJoinLog> nList = new ArrayList<>();
            for(CrossBanquetAutoJoinLog log : joinLogList){
                if(nList.size() < logLimit){
                    nList.add(log);
                }else if(!log.isDealReward()){
                    nList.add(log);
                }
            }
            this.joinLogList = nList;
        }
    }
}
